package com.ljx.controller;

import com.ljx.common.ResponseResult;
import com.ljx.domain.entity.Link;
import com.ljx.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 李捷禧
 * Date: 2023/4/23
 * ClassName: LinkController
 */
@RestController
@RequestMapping("/content/link")
public class LinkController {

    @Autowired
    private LinkService linkService;

    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize, String name, String status){
        return linkService.listAll(pageNum,pageSize,name,status);
    }

    @PostMapping
    public ResponseResult add(@RequestBody Link link){
        linkService.save(link);
        return ResponseResult.okResult("添加成功");
    }

    @GetMapping("{id}")
    public ResponseResult getOne(@PathVariable Long id){
        Link link = linkService.getById(id);
        return ResponseResult.okResult(link);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Link link){
        linkService.updateById(link);
        return ResponseResult.okResult("修改成功");
    }

    @DeleteMapping("{id}")
    public ResponseResult delete(@PathVariable List<Long> id){
        linkService.removeByIds(id);
        return ResponseResult.okResult("删除成功");
    }

}
